﻿using BZhanHengjicvWPF.Common;
using MaterialDesignThemes.Wpf;
using Newtonsoft.Json.Converters;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BZhanHengjicvWPF.ViewModels
{
    public class MsgViewModel : BindableBase, IDialogHostAware
    {
        public string DialogHostName { get; set; } = "Root";

        private string title;
        private string content;
        public string Title
        {
            get { return title; }
            set { title = value; RaisePropertyChanged(); }
        }
        public string Content
        {
            get { return content; }
            set { content = value; RaisePropertyChanged(); }
        }

        public DelegateCommand SaveCommand { get { return new DelegateCommand(Save); } }
        public DelegateCommand CancelCommand { get { return new DelegateCommand(Cancel); } }

        private void Cancel()
        {
            if (DialogHost.IsDialogOpen(DialogHostName))
                DialogHost.Close(DialogHostName,new DialogResult(ButtonResult.No));
        }
        private void Save()
        {

            if (DialogHost.IsDialogOpen(DialogHostName))
            {
                DialogParameters param = new DialogParameters();
                DialogHost.Close(DialogHostName, new DialogResult(ButtonResult.OK, param));
            }
        }
        public void OnDialogOpen(IDialogParameters parameters)
        {
            if (parameters.ContainsKey("Title")) Title = parameters.GetValue<string>("Title");
            if (parameters.ContainsKey("Content")) Content = parameters.GetValue<string>("Content"); 
        }
    }
}
